var swipeshow_render = jQuery.extend(true, {}, base_render, {
    _gen_swipeshow_content: function(imgs){
        var img_swaps = [], img_left_descs = [], img_right_positions = [];
        for(var i = 0, len = imgs.length; i < len; i++){
            img_swaps.push('<div class="img-swap"><img class="scale" src="'+ URL_PREFIX + imgs[i].url+'" alt="'+imgs[i].desc+'" /></div>');
            img_left_descs.push('<li ' + (i != 0 ? 'class="hidden"' : "") + ' >'+imgs[i].desc+'</li>');
            img_right_positions.push('<li><span ' + (i == 0 ? 'class="on"' : "") + ' ></span></li>');
        }
        return {
            imgs:    img_swaps.join(""),
            left:    img_left_descs.join(""),
            right:   img_right_positions.join("")
        };
    },

    components:{
        slider: "",
        slider_nav: ""
    },

    options:{
        continuous: true,
        speed: 200,
        auto: 0,
        stopPropagation: true
    },

    handler: function(imgs){
        var _render = this;
        var slider = _render.components.slider;
        var slider_nav = _render.components.slider_nav;
        if(slider.length && slider_nav.length){
            var content = _render._gen_swipeshow_content(imgs);
            slider.children("div.swipe-wrap").html(content.imgs)
                .find("img").eq(0).one('load', function(){
                    _render.post_render();
                }).each(function(){
                    if(this.complete) $(this).load();
                });
            slider_nav.children("nav.left").html(content.left);
            slider_nav.children("nav.right").html(content.right);
            var right_lis = slider_nav.children("nav.right").find("li");
            var left_lis = slider_nav.children("nav.left").find("li");

            if(imgs.length){
                slider.css({"visibility":"visible", "display":""});
                slider_nav.css({"visibility":"visible", "display":""});
                new Swipe(slider.get()[0], jQuery.extend(_render.options, {
                    callback: function(pos){
                        if(left_lis.length == 2){
                            //handle for situation when slides count is 2, which is a special case in swipe.js
                            pos = pos%2;
                        }
                        left_lis.addClass("hidden").eq(pos).removeClass("hidden");
                        right_lis.find("span").removeClass("on").end().eq(pos).children("span").addClass("on");
                    }
                }));
            }
            else{
                slider.css({"display":"none", "visibility":""});
                slider_nav.css({"display":"none", "visibility":""});
            }
        }
    },
});

